<?php

/*-----------------------------
	function:	_path
	introduce:	返回指定的文件地址
	author:		corrie
------------------------------*/
function _path($name) {
	global $confdir, $moddir, $formdir, $prodir, $memdir, $ctrldir, $incdir, $classdir, $funcdir, $libdir;
	list ( $dir, $file ) = explode ( '/', $name );
	switch ($dir) {
		case 'conf' :
			$path = $confdir . $file . '.conf.php';
			break;
		case 'ctrl' :
			$path = $ctrldir . $file . '.ctrl.php';
			break;
		case 'mod' :
			$path = $moddir . $file . '.mod.php';
			break;
		case 'pro' :
			$path = $prodir . $file . '.pro.php';
			break;
		case 'inc' :
			$path = $incdir . $file . '.inc.php';
			break;
		case 'class' :
			$path = $classdir . $file . '.class.php';
			break;
		case 'func' :
			$path = $funcdir . $file . '.func.php';
			break;
		case 'lib' :
			$path = $libdir . $file . '.lib.php';
			break;
		case 'libx' :
			$path = $libdir . $file . '.libx.php';
			break;
		case 'mem' :
			$path = $memdir . $file . '.mod.php';
			break;
		case 'form' :
			$path = $formdir . $file . '.form.php';
			break;
	}
	if (file_exists ( $path )) {
		return $path;
	} else {
		echo $path;
		return $moddir . '404.mod.php';
	}
}

function import($str) {
	static $imported = array ();
	if (! $imported [$str]) {
		$path = APP_ROOT . str_replace ( '/', DIR_SEP, $str ) . '.php';
		$imported [$str] = true;	
		if (file_exists ( $path )) {
			return include_once ($path);
		} else {
			exit ( "Import Error:$path not found!" );
		}
	}
}


function jump($status, $title, $messages = array(), $forward = '', $links = '', $time_wait = 3) {
	global $tpl;
	//$status	contains: error, notice, alert, finish, good	[(low)---->(high)];
	$tpl->assign ( 'status', $status );
	$tpl->assign ( 'notice', $messages );
	$tpl->assign ( 'title', $title );
	$tpl->assign ( 'links', $links );
	$tpl->assign ( 'forward', $forward ? $forward : ($_REQUEST ['forward'] ? $_REQUEST ['forward'] : ($_SERVER ['HTTP_REFERER'] != '' ? $_SERVER ['HTTP_REFERER'] : NXHOST)) );
	$tpl->assign ( 't_wait', $time_wait * 1000 );
	$tpl->display ( 'jump.htm' );
	exit ();
}

function verify($code = '') {
	if (! $code)
		$code = $_REQUEST ['vcode'];
	if (isset ( $_SESSION ['securimage_code_value'] ) && ! empty ( $_SESSION ['securimage_code_value'] )) {
		if ($_SESSION ['securimage_code_value'] == strtolower ( trim ( $code ) )) {
			$_SESSION ['securimage_code_value'] = '';
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}
?>